package com.tech.koufu.model;

import java.util.ArrayList;
import java.util.Arrays;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

public class CompetitionGroupDetail  implements Parcelable{

	 public String groupId;
	 public String userName;
	 public String startTime;
	 public String endTime;
	 public String isMember;
	 public ArrayList<CompetitionGroupUser> groupUsers = new ArrayList<CompetitionGroupUser>();
	 public String groupName;
	 public String introduction;
	 public CompetitionGroupDetail(){
		 
	 }
	 public CompetitionGroupDetail(JSONObject object){
		 userName = object.optString("user_name");
		 groupName = object.optString("name");
		 startTime = object.optString("starttime");
		 endTime = object.optString("endtime");
		 isMember = object.optString("isMember");
		 introduction = object.optString("introduction");
		 JSONArray ua = object.optJSONArray("users");
		 if(ua!=null ){
			 int length = ua.length();
			 groupUsers = new ArrayList<CompetitionGroupUser>();
			 for(int i=0;i<length;i++){
				 try {
					CompetitionGroupUser cguser= new CompetitionGroupUser(ua.getJSONObject(i));
					groupUsers.add(cguser);
				} catch (JSONException e) { 
					e.printStackTrace();
				} 
			 }
		 }
		 
	 }
	 public CompetitionGroupDetail(Parcel parcel){
		 this.groupId = parcel.readString();
		 userName = parcel.readString();
		 startTime = parcel.readString();
		 endTime = parcel.readString();
		 this.isMember = parcel.readString(); 
		 this.introduction = parcel.readString();
		 parcel.readList(groupUsers, CompetitionGroupUser.class.getClassLoader());
		 groupName = parcel.readString();
	 }
	 public static final Parcelable.Creator<CompetitionGroupDetail> CREATOR = new Creator<CompetitionGroupDetail>() {
		
		@Override
		public CompetitionGroupDetail[] newArray(int size) { 
			return new CompetitionGroupDetail[size];
		}
		
		@Override
		public CompetitionGroupDetail createFromParcel(Parcel source) { 
			return new CompetitionGroupDetail(source);
		}
	};
	@Override
	public int describeContents() { 
		return 0;
	}
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(groupId);
		dest.writeString(userName);
		dest.writeString(startTime);
		dest.writeString(endTime);
		dest.writeString(isMember);
		dest.writeString(introduction);
		dest.writeList(groupUsers);
		dest.writeString(groupName);
		
	}
}
